<?php

namespace app\admin\controller;

use app\admin\model\Admin;
use app\admin\model\User;
use app\common\controller\Backend;
use app\common\model\AdvLists;
use app\common\model\Attachment;
use fast\Date;
use think\Db;

/**
 * 控制台
 *
 * @icon   fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {

        // 广告链接
        $adv_url = 'mu7le.top';
        $qrcode = 'https://img10.360buyimg.com/imgzone/jfs/t20251014/3605/25/26437/2597/66de726cF9ab89429/d7a85c2542da4c31.png';
        $qrcode_end_text = "<div class='text-danger'>遇到问题或者有好的建议可以联系上方图片的微信</div><div class='text-info'>有论坛需要活跃投稿的，可以联系我</div><div class='text-info'>联系Q：7108945</div><div><a class='text-danger' href='https://gitee.com/min-character/beggars-adter' target='_blank'>查看使用介绍和更新记录</a></div>";

        $total_data = [];
        $total_data[] = $this->getValues('使用中', new AdvLists(), ['status'=>1], 'adv/lists');

        // 处理广告链接
        $adv_url = preg_match("/^(http:\/\/|https:\/\/)$/",$adv_url) ? $adv_url : 'http://'.$adv_url;
        $version_data = [
            'version' => config('version'),
            'update_logs_url' => 'https://gitee.com/min-character/beggars-adter'
        ];
        $this->assign('total_data', $total_data);
        $this->assign('version_data', $version_data);
        $this->assign('adv_url',$adv_url);
        $this->assign('qrcode',$qrcode);
        $this->assign('qrcode_end_text',$qrcode_end_text);
        return $this->view->fetch();
    }
    public function getValues($title,$model,$where,$url,$extend=[]){
        return [
            'title' => $title,
            'value' => $extend['value'] ?? $model->where($where)->count(),
            'url' => $url ?? url($url),
            'a_class' => $extend['a_class'] ?? 'text-info',
        ];
    }

}
